package protocol.transactions;

import org.json.JSONObject;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;

import com.netease.http.THttpRequest;

public class CheckTransaction extends XoneBaseTransaction {
	
    String mPhoneNumber;
	public CheckTransaction(String phonenumber) {
		super(TRANSACTION_TYPE_CHECK_PHONENUMBER);
		mPhoneNumber = phonenumber;
	}

	@Override
	protected void onXoneTransactionSuccess(int code, Object obj) {
		if(obj !=null && obj instanceof JSONObject) {
			JSONObject json = (JSONObject) obj;
			int status = json.optInt("status");
			if(status ==0 ){
				notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, Boolean.TRUE);
			} else {
				notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, Boolean.FALSE);
			}
			
		}
		
	}

	@Override
	public void onTransact() {
		THttpRequest request = XoneProtocol.getInstance().createCheckPhoneNumberRequest(mPhoneNumber);
		sendRequest(request);
	}

}
